package com.ptszyxx.popose.module.main.mine.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.ysg.base.BaseViewModel;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.HttpUtils;
import com.ysg.http.data.CommonRepository;
import com.ysg.http.data.entity.exchange.ExchangeResult;

import java.util.HashMap;
import java.util.Map;

public class MineExchangeRecordVM extends BaseViewModel<CommonRepository> {
    public ObservableField<ExchangeResult> entity = new ObservableField();

    public MineExchangeRecordVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onRefreshEvent = new SingleLiveEvent<>();
    }


    //=========================================接口：start===========================================
    @Override
    public void requestList(boolean refresh) {
        if (refresh){
            page = 1;
        }else {
            page ++;
        }

        Map<String, String> map = new HashMap<>();
        map.put("pageno", String.valueOf(page));
        HttpUtils.getInstance()
                .list(model.exchangeRecordList(map), this, (v)->{
                    uc.onRefreshEvent.setValue(v.getData());
                });
    }
}
